package com.jrui.www.t7manager.util;

import com.jrui.www.t7manager.CardSettingBean;
import com.jrui.www.t7manager.EnumEntry;

import java.util.List;

/**
 * Created by xdl on 2019/5/25.
 */

public class T7Util {

    //    如果是枚举类型的参数 根据当前的value 返回对应的 枚举的下标
    public static int getCurrentIndex(CardSettingBean cardSettingBean) {
        int result = -1;
        String value = null;
        if (cardSettingBean.getValue() != null) {
            value = cardSettingBean.getValue();
        } else if (cardSettingBean.getDefaultValue() != null) {
            value = cardSettingBean.getDefaultValue();
        }

        if (value != null) {
            List<EnumEntry> enumEntries = cardSettingBean.getEnumEntry();
            for (int i = 0; i < enumEntries.size(); i++) {
                if (enumEntries.get(i).getValue().equals(value)) {
                    result = i;
                }
            }
        }
        return result;
    }

    //    如果参数设置是枚举类型 根据当前的value获取对应的displayName
    public static String getDisplayNameByValue(String value, List<EnumEntry> enumEntries) {
        String result = "";
        for (EnumEntry enumEntry : enumEntries) {
            if (enumEntry.getValue().equals(value)) {
                result = enumEntry.getDisplayName();
            }
        }
        return result;
    }

    public static String getValue(CardSettingBean cardSettingBean) {
        String result = cardSettingBean.getValue();
        if (result == null) {
            result = cardSettingBean.getDefaultValue();
        }
        return result;
    }
}
